/*
 * @Author: szx
 * @Date: 2022-03-29 12:34:20
 * @LastEditTime: 2022-03-29 12:39:43
 * @Description:
 * @FilePath: \leetcode\2000-2099\2024\2024.js
 */
/**
 * @param {string} answerKey
 * @param {number} k
 * @return {number}
 */
var maxConsecutiveAnswers = function (answerKey, k) {
    return Math.max(findSubArray(answerKey, k, 'T'), findSubArray(answerKey, k, 'F'));
};

const findSubArray = (nums, k, ch) => {
    let res = 0,
        left = 0,
        sums = 0;
    for (let right = 0; right < nums.length; right++) {
        if (nums[right] == ch) sums++;
        while (sums > k) {
            if (nums[left] == ch) sums--;
            left++;
        }
        res = Math.max(res, right - left + 1);
    }
    return res;
};
